package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.PerformanceAppeal;
import com.amsp.oa.oademo.service.PerformanceAppealService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/performance-appeal")
@Tag(name = "绩效考评申诉管理")
@CrossOrigin
public class PerformanceAppealController {

    @Autowired
    private PerformanceAppealService appealService;

    @GetMapping("/list")
    @Operation(summary = "获取绩效考评申诉列表")
    public IPage<PerformanceAppeal> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String department,
            @RequestParam(required = false) String directSuperior,
            @RequestParam(required = false) String handler,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate) {

        return
                appealService.getPage(current, size, name, department, directSuperior, handler, startDate, endDate);
    }

    @GetMapping("/{id}")
    @Operation(summary = "获取绩效考评申诉详情")
    public PerformanceAppeal getById(@PathVariable Long id) {
        return appealService.getById(id);
    }

    @PostMapping("/save")
    @Operation(summary = "保存绩效考评申诉")
    public Boolean save(@RequestBody PerformanceAppeal appeal) {
        if (appeal.getId() != null) {
            return appealService.updateById(appeal);
        }
        return appealService.save(appeal);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除绩效考评申诉")
    public Boolean delete(@PathVariable Long id) {
        return appealService.removeById(id);
    }
}